# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Rémy Oudompheng <remy@archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - set ARM architectures to use linux-thr profile
#  - sed to remove -m32 from CFLAGS

pkgname=tachyon
pkgver=0.98.9
pkgrel=3
pkgdesc="Multithreaded ray tracing software"
arch=('i686' 'x86_64')
url="http://jedi.ks.uiuc.edu/~johns/raytracer/"
license=('BSD')
depends=('libjpeg-turbo' 'libpng')
makedepends=()
source=("http://jedi.ks.uiuc.edu/~johns/raytracer/files/$pkgver/$pkgname-$pkgver.tar.gz" 'enable-jpeg-png.patch')
md5sums=('eb39e10bb37bccc949b45b8fc28dabd7'
         'e0f0c2bd974d0beac509d6dd237ad77c')

case "$CARCH" in
  arm*) _target=linux-thr ;;
  "i686") _target=linux-thr ;;
  "x86_64") _target=linux-64-thr ;;
esac

prepare(){
  cd $pkgname
# enable JPEG and PNG support
  patch -p0 -i "$srcdir"/enable-jpeg-png.patch

  # remove -m32 for ARM
  sed -i 's/-m32//g' unix/Make-arch
}

build() {
  cd $pkgname/unix
  make $_target
}

package() {
  cd $pkgname/compile/$_target
  install -D -m 755 tachyon $pkgdir/usr/bin/tachyon
  install -D -m 644 libtachyon.a $pkgdir/usr/lib/libtachyon.a

  cd $srcdir/$pkgname/scenes
  install -d "$pkgdir"/usr/share/tachyon/scenes/imaps
  install -m 644 README *.dat *.cam *.ac "$pkgdir"/usr/share/tachyon/scenes
  install -m 644 imaps/* "$pkgdir"/usr/share/tachyon/scenes/imaps

  install -d "$pkgdir"/usr/share/licenses/tachyon
  install $srcdir/$pkgname/Copyright "$pkgdir"/usr/share/licenses/tachyon
}
